var app = getApp(),
    util = require("../../../utils/util.js");

const date = new Date();
const yearList = [];
const monthList = [];
for (let i = 1990; i <= date.getFullYear(); i++) {
    yearList.push(i)
}

for (let i = 1; i <= 12; i++) {
    monthList.push(i)
}

Page({
    data: {
        yearList: yearList,
        monthList: monthList,
        month: 1,
        value: [9999, date.getMonth()],
        pagenum: 1,
        storelist: [],
        order_list: [],
        mygd: !1,
        jzgd: !0,
    },
    onLoad: function(t) {
        var e = this,
            mm = parseInt(date.getMonth()) + 1;
        mm = mm < 10 ? '0' + mm : mm;
        app.setNavigationBarColor(e);
        e.setData({
            start_time: date.getFullYear() + "-" + mm,
            start_timeText: date.getFullYear() + "年" + mm + "月",
        })
        e.getMoney();
        e.getRecordList();
    },
    onShow: function() {
        if (wx.getStorageSync("isSJZHOnShow")) {
            this.getMoney();
            this.ConfirmPricker();
        }
        wx.setStorageSync("isSJZHOnShow", false)
    },
    getMoney: function() {
        var e = this,
            a = wx.getStorageSync("sjdsjid");
        app.util.request({
            url: "entry/wxapp/Ktx",
            cachetime: "0",
            data: {
                store_id: a
            },
            success: function(t) {
                e.setData({
                    moneyObj: t.data
                });
            }
        });
    },
    getRecordList: function() {
        wx.showLoading({
            title: '加载中'
        })
        var t,
            a = this,
            e = this.data.table_id,
            s = this.data.status || 1,
            i = this.data.time || "",
            n = wx.getStorageSync("sjdsjid"),
            d = this.data.pagenum,
            o = this.data.start_time;
        1 == s && (t = "1,2,3"),
            2 == s && (t = "1"),
            3 == s && (t = "2"),
            4 == s && (t = "3"),
            app.util.request({
                url: "entry/wxapp/StoreTxList",
                cachetime: "0",
                data: {
                    state: t,
                    time: o,
                    store_id: n,
                    page: d,
                    pagesize: 10
                },
                success: function(t) {
                    t.data.length < 10 ?
                        a.setData({
                            mygd: !0,
                            jzgd: !0
                        }) :
                        a.setData({
                            jzgd: !0,
                            pagenum: a.data.pagenum + 1
                        });
                    var e = a.data.storelist;
                    e = function(t) {
                            for (var e = [], a = 0; a < t.length; a++) - 1 == e.indexOf(t[a]) && e.push(t[a]);
                            return e;
                        }
                        (e = e.concat(t.data)),
                        a.setData({
                            order_list: e,
                            storelist: e
                        });
                    wx.hideLoading();
                },
                complete: function(t) {
                    wx.hideLoading();
                }
            });
    },
    onReachBottom: function() {
        !this.data.mygd && this.data.jzgd && (
            this.setData({
                jzgd: !1
            }),
            this.getRecordList()
        );
    },
    // 选择时间
    ShowPricker: function() {
        this.setData({
            isShowPricker: true,
        })
    },
    bindChange: function(e) {
        let val = e.detail.value;
        let mm = this.data.monthList[val[1]];
        mm = mm < 10 ? '0' + mm : mm;
        this.setData({
            start_time: this.data.yearList[val[0]] + "-" + mm,
            start_timeText: this.data.yearList[val[0]] + "年" + mm + "月",
        });
    },
    ClosePricker: function() {
        this.setData({
            isShowPricker: false,
        })
    },
    ConfirmPricker: function() {
        this.setData({
            isShowPricker: false,
            pagenum: 1,
            order_list: [],
            storelist: []
        });
        this.getRecordList();
    },
});